﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MeetingEmployee.aspx.cs"
    Inherits="Meeting.Web.Admin.MeetingSet.MeetingEmployee" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>会议人员</title> 
    <link href="../../Css/main.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/jquery-1.8.2.min.js"></script>
      <!--ardialog-->
    <script type="text/javascript" src="../../Scripts/artDialog4.1.6/artDialog.js?skin=blue"></script>
    <script type="text/javascript" src="../../Scripts/artDialog4.1.6/plugins/iframeTools.js"></script>
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/cupertino/easyui.css" />
    <script type="text/javascript" src="../../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../Scripts/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../../Scripts/common.js"></script>
    <script src="../../Scripts/Json2.js" type="text/javascript"></script>
    <script type="text/javascript">
        var hostId = "";
        var CategoryId = "";
        var searCount = 0;
      
     
        $(function () {

            $("#meetingName").html(unescape(request("Name")));
            $("#Id").val(request("Id"));
            CategoryId = request("CategoryId");
            InitStandMeeting();
            //获取已选择人员 
            $("#tbEmployee").datagrid({
                url: 'MeetingEditOperation.ashx?method=GetSelEmployee&Id=' + $("#Id").val(),
                singleSelect: true,
                idField: 'EmployeeId'
            });


            $.post("MeetingEditOperation.ashx?method=GetMeetingById", { Id: $("#Id").val() }, function (data) {
                if (data.success == true) {
                    data = data.ResponseData[0];
                    $("#HostId").val(data.HostId);
                    $("#Host").val(data.HostName);
                    $("#RoleId").val(data.HostRoleId);
                    $("#HostTitle").val(data.HostTitle);

                } else {
                    $("#error").val(data.Message); $.messager.alert("提示", data.Message);
                }
            });
            $("#editSelect").hide();
        });

        //添加与会人员
        function AddEmployee() {

            var rolestr = "";
            $.post("MeetingEditOperation.ashx?method=GetCategoryById&Id=" + CategoryId, function (data) {
                if (data) {
                    rolestr = data[0].RoleId;
                    if (rolestr == "" || rolestr == undefined) {
                        $.messager.alert("获取会议角色失败");
                        return;
                    }
                    var radStr = Math.random();
                    var url = "../SelectBase/SelectOAUser.aspx" + '?Radstr=' + radStr + "&RoleId=" + rolestr;
                    art.dialog.open(url, {
                        id: 'AddEmployee', title: '选择参会人', width: 500, height: 430, lock: true,
                        close: function () {
                            var selNodeJson = art.dialog.data('selNode'); // 读取人员选择返回值
                            //  alert(selNodeJson);
                            if (selNodeJson != "") {
                                try {
                                    var data = JSON.parse(selNodeJson);
                                    DelAll();
                                    for (i = 0; i < data.length; i++) {
                                        $('#tbEmployee').datagrid('appendRow', data[i]);
                                    }
                                } catch (ex) { }
                            }
                        }
                    }, true);
                }
            }); 

        }

        function SelectMeetingEmployee() {
            var wName;
            var radStr = Math.random();
            var url = '../SelectBase/SelectMeetingUser.aspx?Id=' + $("#Id").val() + '&HostId=' + hostId + '&SeatCount=' + searCount + '&Radstr=' + radStr;
            art.dialog.open(url, {
                id: 'AAA', width: 430, height: 380, lock: true,
                close: function () {
                    var flag = art.dialog.data('result'); // 读取返回值True表示正确
                    $("#FlagSaveOk").val(flag);
                    $("#selName").html(art.dialog.data('selName'));
                    $("#selId").html(art.dialog.data('selId'));
                }
            }, false);
        }

        //设置显示
        function InitStandMeeting() {
            //会议类型
            $("#StandMeeting").combobox({
                url: 'MeetingOperation.ashx?method=GetStandMeeting&CategoryId=' + CategoryId,
                valueField: 'Id',
                textField: 'Name',
                onSelect: function (itm) {  //获取常设会议配置人员 
                    $("#tbEmployee").datagrid({
                        url: "../MeetingStand/StandMeetingOperation.ashx?method=GetMeetingEmployeeById&Id=" + itm.Id
                    });
                }
            });
        }
       
  
        function DelAll() {
            var rows = $('#tbEmployee').datagrid('getRows');
            for (i = rows.length - 1; i >= 0; i--) {
                $('#tbEmployee').datagrid('deleteRow', i);
            }
        }

       
        function DelGrid(tn) {
            if (tn.nodetype != "user") return;
            var index = $('#tbEmployee').datagrid('getRowIndex', tn.account);
            $('#tbEmployee').datagrid('deleteRow', index);
        }
        function EditSort() {
            var rows = $('#tbEmployee').datagrid('getRows');
            for (i = 0; i < rows.length; i++) {
                $('#tbEmployee').datagrid('beginEdit', i);
            }
        }

        //选择人员选取方式
        function SetSelectEmpoyee(obj) {
//            var rows = $('#tbEmployee').datagrid('getRows');
//            for (i = rows.length - 1; i >= 0; i--) {
//                var row = rows[i];
//                var index = $('#tbEmployee').datagrid('getRowIndex', row);
//                $('#tbEmployee').datagrid('deleteRow', index);
//            }
            if ($(obj).attr("checked") == "checked") {
                if ($(obj).val() == "oa") {
                    $("#trStandMeeting").hide();
                    $("#editSelect").show();
                }
                else {
                    $("#trStandMeeting").show();
                    $("#editSelect").hide();
                    //读取常设会议信息
                    InitStandMeeting();
                }
            }

        }
 
        //设置主持人
        function SetHost() {
            var row = $("#tbEmployee").datagrid("getSelected");
            if (row) {
                $("#HostId").val(row.EmployeeId);
                $("#Host").val(row.EmployeeName);
                $("#RoleId").val(row.RoleId);
                $("#HostTitle").val(row.EmployeeTitle);
            }
        }
        //获取已选择人员
        function GetSelectEmployee() {
            var rows = $('#tbEmployee').datagrid('getRows');
            for (i = 0; i < rows.length; i++) {
                var ed = $('#tbEmployee').datagrid('getEditor', { index: i, field: 'Sort' });

                if (ed != null && $(ed.target).val() == "") $(ed.target).val("10");
                $('#tbEmployee').datagrid('endEdit', i);
            }
            var data = $("#tbEmployee").datagrid("getData");
            if (data) return data.rows;
            return "";
        }
        //保存参会人员
        function SaveMeetingEmployee() {
            //验证表单
            if ($("#form1").form('validate') == false) {
                return;
            }
            //获取选中人员
            var selEmployee = GetSelectEmployee();
            if (selEmployee == "") {
                $.messager.alert("提示", "请选择参会人员");
                return false;
            }
            selEmployee = JSON.stringify(selEmployee);

            var Id = $("#Id").val(); //会议ID            
            var HostId = $("#HostId").val();
            var Host = $("#Host").val();
            var HostRoleId = $("#RoleId").val();
            var HostTitle = $("#HostTitle").val();
            //
            var postData = { Id: Id, HostId: HostId, Host: Host, HostRoleId: HostRoleId, HostTitle: HostTitle,
                selEmployee: selEmployee
            };
            //提交 
            $.post("MeetingOperation.ashx?method=SaveMeetingEmployee", postData, function (data) {
                if (data.success == true) {
                    $.messager.alert("提示", "保存成功");
                    //保存成功，退出当前对话框
                    art.dialog.close();
                } else {
                    $.messager.alert("提示", "保存失败：" + data.Message);
                }
            });
        }

    </script>
    <style type="text/css">
        .chk
        {
            border: 0;
        }
        input type[radio]
        {
            border: 0;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="hidden" id="Id" />
        <input type="hidden" id="FlagSaveOk" />
        <table class="showView1" cellpadding="0" cellspacing="0" align="center">
            <tr>
                <td class="title">
                    会议名称:
                </td>
                <td class="td_Modify1" style="">
                    <span id="meetingName"></span>
                </td>
            </tr>
            <tr>
                <td class="title">
                    来源选择:
                </td>
                <td class="td_Modify1" style="">
                    <input type="radio" value="stand" class="chk" name="sel" onclick="SetSelectEmpoyee(this);"
                        checked="checked" id="Radio1" />常设会议
                    <input type="radio" value="oa" class="chk" name="sel" onclick="SetSelectEmpoyee(this);"
                        id="oaUser" />电子政务获取
                </td>
            </tr>
            <tr id="trStandMeeting">
                <td class="title">
                    常设会议:
                </td>
                <td class="td_Modify1" style="">
                    <input id="StandMeeting" class="easyui-combobox" style="width: 403px; line-height: 25px;">
                </td>
            </tr>
            <tr>
                <td class="title">
                    参会人员:
                </td>
                <td class="td_Modify1">
                    <a id="editSelect" class="easyui-linkbutton" onclick="AddEmployee();">选择参会人</a>
                    <a id="editSort" class="easyui-linkbutton" onclick="EditSort();">编辑排序</a>
                    <table id="tbEmployee" loadmsg="正在处理数据请等待..." class="easyui-datagrid" singleselect="true"
                        style="width: 500px; height: 250px">
                        <thead>
                            <tr>
                                <th data-options="field:'EmployeeId',hidden:true">
                                    编号
                                </th>
                                <th data-options="field:'EmployeeName',width:100">
                                    姓名
                                </th>
                                <th data-options="field:'RoleId',hidden:true">
                                    编号
                                </th>
                                <th data-options="field:'EmployeeTitle',width:100 ">
                                    职务
                                </th>
                                 <th data-options="field:'Mobile',width:100">
                                    手机
                                </th>
                                <th data-options="field:'Sort',width:100,editor:'text'">
                                    排序
                                </th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
            <tr>
                <td class="title">
                    会议主持人:
                </td>
                <td class="td_Modify1">
                    <input type="hidden" id="HostId" /><input type="hidden" id="RoleId" /><input type="hidden"
                        id="HostTitle" />
                    <input id="Host" type="text" class="easyui-validatebox" readonly="readonly" style="width: 360px"
                        required="true" /><a class="easyui-linkbutton" onclick="SetHost();">设置主持人</a>
                </td>
            </tr>
            <tr>
                <td class="title">
                    &nbsp;
                </td>
                <td class="td_Modify1">
                    <a class="easyui-linkbutton" onclick="SaveMeetingEmployee();">保存参会人员</a>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
